package models

import (
	"web/global"
)

const (
	ORDER_STATUS_UNPAID int8 = iota + 1 // 从 1 开始
	ORDER_STATUS_PAID
	ORDER_STATUS_FINISHED
	ORDER_STATUS_CANCELLED
	ORDER_STATUS_REFUNDING
	ORDER_STATUS_REFUNDED
)

var OrderStatusDescription = map[int8]string{
	ORDER_STATUS_UNPAID:    "未支付",
	ORDER_STATUS_PAID:      "已支付",
	ORDER_STATUS_FINISHED:  "已完成",
	ORDER_STATUS_CANCELLED: "已取消",
	ORDER_STATUS_REFUNDING: "退款中",
	ORDER_STATUS_REFUNDED:  "已退款",
}

func (LaOrder) EnumStatus(value ...int) interface{} {
	data := map[int]string{
		1: "未支付",
		2: "已支付",
		3: "已完成",
		4: "已取消",
		5: "退款中",
		6: "已退款",
	}

	if len(value) > 0 {
		return data[value[0]]
	}
	return data
}

func (LaOrder) EnumPayStatus(value ...uint8) interface{} {
	data := map[uint8]string{
		0: "未支付",
		1: "已支付",
	}

	if len(value) > 0 {
		return data[value[0]]
	}
	return data
}

type LaOrder struct {
	global.BaseModel
	Uid            uint64  `gorm:"column:uid;type:bigint(20) unsigned;default:0" json:"uid"`
	ServiceTime    string  `gorm:"column:service_time;type:varchar(25)" json:"service_time"`
	Sn             string  `gorm:"column:sn;type:varchar(20)" json:"sn"`
	OrderNo        string  `gorm:"column:order_no;type:varchar(20);default:''" json:"order_no"`
	UserCouponID   int     `gorm:"column:user_coupon_id;type:int(11)" json:"user_coupon_id"`
	Coupon         string  `gorm:"column:coupon;type:varchar(255)" json:"coupon"`
	Address        string  `gorm:"column:address;type:varchar(255)" json:"address"`
	Status         int     `gorm:"column:status;type:int(3);default:10" json:"status"`
	Remark         string  `gorm:"column:remark;type:varchar(255)" json:"remark"`
	PayType        int     `gorm:"column:pay_type;type:int(2);default:1" json:"pay_type"`
	PayTrade       string  `gorm:"column:pay_trade;type:varchar(80);default:''" json:"pay_trade"`
	PayStatus      uint8   `gorm:"column:pay_status;type:tinyint(1) unsigned;default:0" json:"pay_status"`
	OrderAmount    float64 `gorm:"column:order_amount;type:decimal(20,2);default:0.00" json:"order_amount"`
	PayAmount      float64 `gorm:"column:pay_amount;type:decimal(20,2);default:0.00" json:"pay_amount"`
	PayRemark      string  `gorm:"column:pay_remark;type:varchar(255);default:''" json:"pay_remark"`
	IsAppraise     uint8   `gorm:"column:is_appraise;type:tinyint(1);default:0" json:"is_appraise"`
	CancelRemark   string  `gorm:"column:cancel_remark;type:varchar(200);default:''" json:"cancel_remark"`
	CancelDatetime string  `gorm:"column:cancel_datetime;type:varchar(25)" json:"cancel_datetime"`
}

// 订单产品
type LaOrderProject struct {
	global.BaseModel
	OrderID   uint    `gorm:"column:order_id;type:int(11) unsigned;not null;default:0" json:"order_id"`
	OrderCode string  `gorm:"column:order_code;type:varchar(255);not null;default:''" json:"order_code"`
	ProjectID int     `gorm:"column:project_id;type:int(10);not null" json:"project_id"`
	Project   string  `gorm:"column:project;type:varchar(10);not null;default:0.00" json:"project"`
	Price     float64 `gorm:"column:price;type:decimal(10,2);not null;default:0.00" json:"price"`
	Duration  int     `gorm:"column:duration;type:int(6);default:60" json:"duration"`
	Count     int     `gorm:"column:count;type:int(6);not null;default:1" json:"count"`
}

// 订单评价
type LaOrderEvaluate struct {
	global.BaseModel
	OrderID uint64 `gorm:"column:order_id;type:bigint(20) unsigned;not null" json:"order_id"`
	Uid     int    `gorm:"column:uid;type:int(20)" json:"uid"`
	Star    uint8  `gorm:"column:star;type:tinyint(1)" json:"star"`
	Content string `gorm:"column:content;type:varchar(255)" json:"content"`
	Tag     string `gorm:"column:tag;type:varchar(255)" json:"tag"`
	IsAnony uint8  `gorm:"column:is_anony;type:tinyint(1) unsigned zerofill;default:0" json:"is_anony"`
}

func (LaOrder) TableName() string {
	return "la_order"
}
func (LaOrderEvaluate) TableName() string {
	return "la_order_evaluate"
}
func (LaOrderProject) TableName() string {
	return "la_order_project"
}
